package com.wc.AlgoOJ.SQ12L3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/14 23:34
 * @description
 */
public class Main2 {
    static FastReader sc = new FastReader();

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        int maxN = (int) 1e6 + 7;
        int[] lastStart = new int[maxN];
        int n = sc.nextInt();
        Arrays.fill(lastStart, -1);
        for (int i = 1; i <= n; i++) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            lastStart[end] = Math.max(lastStart[end], start);
        }
        int ans = 0;
        for (int start = 0, end = 0; end < maxN; end++) {
            if (start <= lastStart[end]) {
                ans++;
                start = end;
            }
        }
        System.out.println(ans);
    }

    static class FastReader {
        StringTokenizer st;
        BufferedReader br;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


